<?php
class articleModuleList extends CWidget
{
	public $htmlOptions = array(
		'id'=>'category',
		'class'=>'category'
	);
	
	public $view = 'list';
	
	public $cid;
	
	public $data= array();
	
	public function getModel($id)
	{
		$model = Category::model()->getCategoryDeepZeroInfo(Category::model()->findByPk($this->cid)->cate_type);
		
		
		return $model;
	}
	
	
	public function getCategoriesByType($type)
	{
		$result = array();
		
// 		$cateModel = $this->getModel($type);
		
		
// 		$models = Category::model()->getCategoryModelByType($cateModel->cate_type);
		
		$array = Category::model()->findAll();
		
		foreach ($array as $item)
		{
			$result[] = $item->attributes;
		}
		
// 		$variable = Category::model()->getChildrenObject($array, 7);
		
// 		foreach ($variable as $value) {
// 			UtilTools::dump($value);
// 		}

		
// 		$model = Category::model()->findByPk(176);
		
// 		UtilTools::dump($model->parent->attributes);
		
// 		foreach ($model->children as $item)
// 		{
// 			UtilTools::dump($item->attributes);
// 		}
		
		
// 		echo $this->cid;
		
		$cid = Category::model()->findParentZero($this->cid);
		
		$models = Category::model()->getChildrenArray($result,array_pop($cid));
		
		
		return json_decode(json_encode($models));
		
		
		
// 		foreach ($models as $model)
// 		{
// 			$result[] = $model->attributes;
// 		}
		
// 		return $result;
		
// 		return  Category::model()->getChildrenObject($models);	
	
		
	}
	
	
	public function run()
	{
		$this->data = $this->getCategoriesByType($this->cid);
		
		$this->render($this->view,array(
			'model'=>$this->getModel($this->cid)
		));
	}
}
?>